package com.liang.cloud.Controller;

import com.alibaba.fastjson.JSONObject;
import com.liang.cloud.Entity.Cart;
import com.liang.cloud.Service.CartService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 余亮亮
 * @description:
 * @create: 2020-03-26 12:02:34
 **/
@RestController
@RequestMapping("/cart/api")
public class ApiCartController {

    @Resource
    CartService service;


    @GetMapping("/findByOpenid/{openid}")
    List<Cart> findByOpenid(@PathVariable("openid") String openid){
        return service.findByOpenid(openid);
    }


    @PostMapping("/addCart")
    Cart addCart(@RequestBody Cart cart){
        return service.addCart(cart);
    }


    @PostMapping("/sava")
    Cart sava(@RequestBody Cart cart){
        return service.sava(cart);
    }


    @PostMapping("/delete")
    void delete(@RequestBody List<Integer> integerList){
//        System.out.println("cartList"+cartList);
//        List<Integer> list = JSONObject.parseArray(cartList,Integer.class);
         service.delete(integerList);
    }

    @PostMapping("/deleteByOpenid")
    void deleteByOpenid(@RequestParam("openid") String openid){
        service.deleteByOpenid(openid);
    }
}
